using UnityEngine;
using UnityEngine.UI;

namespace Toolkit.UI
{
    [RequireComponent(typeof(Collider2D))]
    public class SelfImage : Image
    {
        private Collider2D _collider;

        private Collider2D GetCollider()
        {
            if (_collider == null)
                _collider = GetComponent<Collider2D>();

            return _collider;
        }

        public override bool IsRaycastLocationValid(Vector2 screenPoint, Camera eventCamera)
        {
            RectTransformUtility.ScreenPointToWorldPointInRectangle(rectTransform, screenPoint, eventCamera, out var point);
            return GetCollider().OverlapPoint(point);
        }
    }
}